import request from '@/utils/request';

export interface Salary {
  id: number;
  className: string;
  position: string;
  name: string;
  idCard: string;
  identifier: string;
  basicSalary: number;
  performanceSalary: number;
  individualBonus: number;
  enterprisePension: number;
  endowmentInsurance: number;
  unemploymentInsurance: number;
  medicalInsurance: number;
  housingFund: number;
  personalTax: number;
  deductionOne: number;
  deductionTwo: number;
  salaryMonth: string;
  createTime: string;
  batchNo: string;
}

export interface SalaryQueryParams {
  current: number;
  size: number;
  keyword?: string;
  className?: string;
  position?: string;
  salaryMonth?: string;
}

export interface SalaryQueryResult {
  records: Salary[];
  total: number;
  size: number;
  current: number;
}

export interface SalaryDTO {
  className: string;
  position: string;
  name: string;
  idCard: string;
  identifier: string;
  basicSalary: number;
  performanceSalary: number;
  individualBonus: number;
  enterprisePension: number;
  endowmentInsurance: number;
  unemploymentInsurance: number;
  medicalInsurance: number;
  housingFund: number;
  personalTax: number;
  deductionOne: number;
  deductionTwo: number;
  salaryMonth: string;
}

// 获取工资列表
export const getSalaryList = (params: SalaryQueryParams) => {
  return request.get<SalaryQueryResult>('/salaries', { params });
};

// 获取工资详情
export const getSalary = (id: number) => {
  return request.get<Salary>(`/salaries/${id}`);
};

// 创建工资记录
export const createSalary = (data: SalaryDTO) => {
  return request.post<void>('/salaries', data);
};

// 更新工资记录
export const updateSalary = (id: number, data: SalaryDTO) => {
  return request.put<void>(`/salaries/${id}`, data);
};

// 删除工资记录
export const deleteSalary = (id: number) => {
  return request.delete<void>(`/salaries/${id}`);
};

// 导入工资数据
export const importSalaries = (file: File, salaryMonth: string) => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('salaryMonth', salaryMonth);
  return request.post<string[]>('/salaries/import', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

// 导出工资数据
export const exportSalaries = (params: SalaryQueryParams) => {
  return request.get('/salaries/export', {
    params,
    responseType: 'blob',
  });
};

// 获取工资月份列表
export const getSalaryMonths = () => {
  return request.get<string[]>('/salaries/months');
}; 